home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / SQL and Data Base / Logic Works ERwin 3.5 / data.1 / ERWIN40.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-06-02  |  20.1 KB  |  753 lines

  1. Attribute VB_Name = "Module2"
  2. Option Explicit
  3.  
  4. Type TranslateItem
  5.     Item As Variant ' index into control or field array
  6.     Value As Variant
  7. End Type
  8.  
  9. Type ListItem
  10.     DisplayVal As String
  11.     DataVal As String
  12. End Type
  13.  
  14. #If Win32 Then ' 32-bit VB uses this Declare.
  15.     Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  16.     Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  17. #Else   ' 16-bit VB uses this Declare.
  18.     Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Long
  19.     Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
  20. #End If
  21.  
  22.  
  23. Function er_CB_ControlValue(cb As Control, fld As Field) As Variant
  24.     er_CB_ControlValue = er_CB_ControlXlateValue(cb, fld, "Y", "N")
  25.  
  26. End Function
  27.  
  28. Function er_CB_ControlXlateValue(cb As Control, fld As Field, sOn As String, sOff As String) As Variant
  29.     Dim nValue As Integer
  30.     Dim sValue As String
  31.     Dim sMsg As String
  32.     Dim nOff As Integer
  33.     Dim nOn As Integer
  34.  
  35.  
  36.     Select Case Abs(cb.Value)
  37.     Case 0
  38.         sValue = sOff
  39.         nValue = Val(sOff)
  40.     Case 1
  41.         sValue = sOn
  42.         nValue = Val(sOn)
  43.     Case Else
  44.         sValue = ""
  45.     End Select
  46.  
  47.     Select Case True
  48.     Case er_FieldIsNumeric(fld)
  49.         er_CB_ControlXlateValue = nValue
  50.     Case er_FieldIsString(fld)
  51.         er_CB_ControlXlateValue = sValue
  52.     Case Else
  53.         Beep
  54.         sMsg = fld.Name & " uses a data type that is not supported by ERwin's code translation feature."
  55.         MsgBox sMsg, MB_OK + MB_ICONEXCLAMATION, "ERwin for Visual Basic"
  56.     End Select
  57.  
  58. End Function
  59.  
  60. Function er_CB_FieldValue(cb As Control, fld As Field) As Integer
  61.     er_CB_FieldValue = er_CB_FieldXlateValue(cb, fld, "Y", "N")
  62.  
  63. End Function
  64.  
  65. Function er_CB_FieldXlateValue(cb As Control, fld As Field, sOn As String, sOff As String) As Integer
  66.     Dim sMsg As String
  67.     Dim sBuff As String
  68.  
  69.  
  70.     If IsNull(fld) Then
  71.         er_CB_FieldXlateValue = 2
  72.     Else
  73.         Select Case True
  74.         Case er_FieldIsNumeric(fld)
  75.             If fld = Val(sOff) Then
  76.                 er_CB_FieldXlateValue = 0
  77.             ElseIf fld = Val(sOn) Then
  78.                 er_CB_FieldXlateValue = 1
  79.             Else
  80.                 er_CB_FieldXlateValue = 2
  81.             End If
  82.         Case er_FieldIsString(fld)
  83.             sBuff = fld
  84.             sBuff = Trim(sBuff)
  85.  
  86.             If sBuff = sOff Then
  87.                 er_CB_FieldXlateValue = 0
  88.             ElseIf sBuff = sOn Then
  89.                 er_CB_FieldXlateValue = 1
  90.             Else
  91.                 er_CB_FieldXlateValue = 2
  92.             End If
  93.         Case Else
  94.             Beep
  95.             sMsg = fld.Name & " uses a data type that is not supported by ERwin's code translation feature."
  96.             MsgBox sMsg, MB_OK + MB_ICONEXCLAMATION, "ERwin for Visual Basic"
  97.         End Select
  98.     End If
  99.  
  100. End Function
  101.  
  102. Function er_CurrRowExists(ds As Data)
  103.     Dim sBookMark As String
  104.     Dim vValue As Variant
  105.  
  106.     On Error GoTo CurrRowExists_Handler
  107.     er_CurrRowExists = True
  108.  
  109.     ' Try to cause the "no current record" error
  110.     vValue = ds.Recordset.Fields(0)
  111.  
  112.     If ds.EditMode = DATA_EDITADD Then
  113.         er_CurrRowExists = False
  114.     End If
  115.  
  116.     Exit Function
  117.  
  118. CurrRowExists_Handler:
  119.     Select Case Err
  120.         Case 3021   ' Error: No current record
  121.             er_CurrRowExists = False
  122.             Resume Next
  123.         Case 91     ' Object variable not set
  124.             er_CurrRowExists = False
  125.             Resume Next
  126.         Case Else
  127.             er_DisplayError (Err)
  128.             Resume Next
  129.     End Select
  130.  
  131. End Function
  132.  
  133. Sub er_DeleteButton(ds As Data)
  134.     If ds.EditMode <> DATA_EDITADD Then
  135.         er_ffDeleteRow ds
  136.     Else
  137.         MoveFromCurrRow ds
  138.     End If
  139.  
  140. End Sub
  141.  
  142. Sub er_DisplayError(ErrNum As Integer)
  143.     Beep
  144.     MsgBox "Error:" & Str(ErrNum) & " - " & Error(ErrNum)
  145.  
  146. End Sub
  147.  
  148. Sub er_DS_Update(Frm As Form, ds As Data, nNoRepos As Integer, bUpdateFailed As Integer)
  149.     Dim bNew As Integer
  150.     Dim bUpdating As Integer
  151.  
  152.     On Error GoTo DS_Update_Handler
  153.  
  154.     bUpdateFailed = False   'MAR
  155.  
  156.     If er_CurrRowExists(ds) = False Then
  157.         bNew = True
  158.     End If
  159.  
  160. '    If er_CurrRowExists(ds) Or ds.EditMode = DATA_EDITADD Then  'MAR
  161.     If ds.EditMode <> DATA_EDITNONE Then
  162.         nNoRepos = nNoRepos + 1
  163.         bUpdating = True
  164.         ds.Recordset.Update
  165.         bUpdating = False
  166.         nNoRepos = nNoRepos - 1
  167.  
  168.         If bNew And Not bUpdateFailed And ds.Recordset.RecordCount Then
  169.             ds.Recordset.MoveLast
  170.             bNew = False
  171.         End If
  172.     End If
  173.  
  174.     Exit Sub
  175.  
  176. DS_Update_Handler:
  177.  
  178.     Select Case Err
  179.         Case 3020   ' Error: Update without Add New or Edit
  180.             Resume Next
  181.  
  182.         Case 3021   ' Error: No current record
  183.             Resume Next
  184.  
  185.         Case Else
  186.             er_DisplayError (Err)
  187.             If bUpdating Then bUpdateFailed = True  'MAR
  188.             Resume Next
  189.     End Select
  190.  
  191.  
  192. End Sub
  193.  
  194. Sub er_ffDeleteRow(ds As Data)
  195.     Dim bLastRecord As Variant
  196.     
  197.     If ds.Recordset.RecordCount = 0 Then Exit Sub
  198.  
  199.     On Error GoTo ErrorHandler
  200.     bLastRecord = False
  201.     
  202.     If ds.Recordset.AbsolutePosition = (ds.Recordset.RecordCount - 1) Then
  203.         bLastRecord = True
  204.     End If
  205.     ds.Recordset.Delete
  206.     If Not er_CurrRowExists(ds) Then
  207.         MoveFromCurrRow ds, bLastRecord
  208.     End If
  209.     If ds.Recordset.RecordCount = 0 Then
  210.         'ds.Recordset.AddNew    'MAR replaced by next line
  211.         ds.Refresh
  212.     End If
  213.  
  214. er_ffDeleteRow_Done:
  215.     Exit Sub
  216.  
  217. ErrorHandler:
  218.  
  219.     Select Case Err
  220.         'Case 3197   ' Error: Data has changed, operation stopped
  221.         '    ds.Recordset.Update
  222.         '    Resume Next
  223.  
  224.         Case 3021   ' Error: No current record
  225.             Resume Next
  226.  
  227.         Case 444    ' Method not applicable in this context
  228.             Resume Next
  229.  
  230.         Case Else
  231.             er_DisplayError (Err)
  232.             Resume er_ffDeleteRow_Done
  233.     End Select
  234.  
  235. End Sub
  236.  
  237. Function er_FieldIsNumeric(fld As Field) As Integer
  238.     Select Case fld.Type
  239.     Case DB_BOOLEAN
  240.         er_FieldIsNumeric = True
  241.     Case DB_BYTE
  242.         er_FieldIsNumeric = True
  243.     Case DB_INTEGER
  244.         er_FieldIsNumeric = True
  245.     Case DB_LONG
  246.         er_FieldIsNumeric = True
  247.     Case DB_CURRENCY
  248.         er_FieldIsNumeric = True
  249.     Case DB_SINGLE
  250.         er_FieldIsNumeric = True
  251.     Case DB_DOUBLE
  252.         er_FieldIsNumeric = True
  253.     Case Else
  254.         er_FieldIsNumeric = False
  255.     End Select
  256.  
  257. End Function
  258.  
  259. Function er_FieldIsString(fld As Field) As Integer
  260.     Select Case fld.Type
  261.     Case DB_TEXT
  262.         er_FieldIsString = True
  263.     Case DB_LONGBINARY
  264.         er_FieldIsString = True
  265.     Case DB_MEMO
  266.         er_FieldIsString = True
  267.     Case Else
  268.         er_FieldIsString = False
  269.     End Select
  270.  
  271. End Function
  272.  
  273. Function er_NullValue(fld As Field) As Variant
  274.     Select Case fld.Type
  275.     Case DB_BOOLEAN
  276.         er_NullValue = 0
  277.     Case DB_BYTE
  278.         er_NullValue = 0
  279.     Case DB_INTEGER
  280.         er_NullValue = 0
  281.     Case DB_LONG
  282.         er_NullValue = 0
  283.     Case DB_CURRENCY
  284.         er_NullValue = 0
  285.     Case DB_SINGLE
  286.         er_NullValue = 0
  287.     Case DB_DOUBLE
  288.         er_NullValue = 0
  289.     Case DB_DATE
  290.         er_NullValue = ""
  291.     Case DB_TEXT
  292.         er_NullValue = ""
  293.     Case DB_LONGBINARY
  294.         er_NullValue = ""
  295.     Case DB_MEMO
  296.         er_NullValue = ""
  297.     End Select
  298.  
  299. End Function
  300.  
  301. Function er_ObjectSet(ds As Data) As Integer
  302.     Dim iMode As Integer
  303.     On Error GoTo ObjectSet_Handler
  304.  
  305.     er_ObjectSet = True
  306.  
  307.     ' Try to cause an error by accessing the data control
  308.     If ds.EditMode = DATA_EDITADD Then iMode = 0 'no op
  309.  
  310.     Exit Function
  311.  
  312. ObjectSet_Handler:
  313.     Select Case Err
  314.     Case 91
  315.         er_ObjectSet = False
  316.         Resume Next
  317.  
  318.     Case Else
  319.         er_DisplayError (Err)
  320.         Resume Next
  321.     End Select
  322. End Function
  323.  
  324. Function er_PreValidate(ds As Data, Action As Integer, Save As Integer) As Integer
  325.     er_PreValidate = False
  326.  
  327.     Select Case Action
  328. '    Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST, DATA_ACTIONDELETE    'MAR changed
  329.     Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST
  330.         If ds.Recordset.RecordCount = 0 And Save = False Then
  331.             'Action = DATA_ACTIONCANCEL 'MAR removed
  332.             Save = False
  333.             er_PreValidate = True
  334.         End If
  335.  
  336.     Case DATA_ACTIONDELETE
  337.         If ds.Recordset.RecordCount = 0 And Save = False Then
  338.             Action = DATA_ACTIONCANCEL
  339.             Save = False
  340.             er_PreValidate = True
  341.         End If
  342.  
  343.     Case DATA_ACTIONUPDATE
  344.         If Save = False Then
  345.             Action = DATA_ACTIONCANCEL
  346.             er_PreValidate = True
  347.         End If
  348.  
  349.     Case DATA_ACTIONBOOKMARK
  350.         er_PreValidate = True
  351.     End Select
  352.  
  353.     Exit Function
  354.  
  355. PreVal_Handler:
  356.     Select Case Err
  357.         Case 3021   ' Error: No current record
  358.             Beep
  359.             Resume Next
  360.  
  361.         Case Else
  362.             er_DisplayError (Err)
  363.             Resume Next
  364.     End Select
  365.  
  366. End Function
  367.  
  368. Sub er_SetEditMode(ds As Data)
  369.     On Error GoTo SetEditMode_Handler
  370.  
  371.     If er_CurrRowExists(ds) And ds.EditMode = DATA_EDITNONE Then
  372.         ds.Recordset.Edit
  373.     End If
  374.  
  375.     Exit Sub
  376.  
  377. SetEditMode_Handler:
  378.     Select Case Err
  379.         'Case 3197   ' Error: Data has changed, operation stopped
  380.         '    Resume Next
  381.  
  382.         Case Else
  383.             er_DisplayError (Err)
  384.             Resume Next
  385.     End Select
  386.  
  387. End Sub
  388.  
  389. Sub er_SetFieldToNull(fld As Field)
  390.     Select Case fld.Type
  391.     Case DB_BOOLEAN
  392.         fld = 0
  393.     Case DB_BYTE
  394.         fld = 0
  395.     Case DB_INTEGER
  396.         fld = 0
  397.     Case DB_LONG
  398.         fld = 0
  399.     Case DB_CURRENCY
  400.         fld = 0
  401.     Case DB_SINGLE
  402.         fld = 0
  403.     Case DB_DOUBLE
  404.         fld = 0
  405.     Case DB_DATE
  406.         fld = Date
  407.     Case DB_TEXT
  408.         fld = ""
  409.     Case DB_LONGBINARY
  410.         fld = ""
  411.     Case DB_MEMO
  412.         fld = ""
  413.     End Select
  414.  
  415. End Sub
  416.  
  417. Function er_SQLValue(ds As Data, sFldName As String)
  418.     Dim bQuotes As Integer
  419.     Dim sValue As String
  420.     Dim vValue As Variant
  421.  
  422.     Select Case ds.Recordset(sFldName).Type
  423.     Case DB_TEXT
  424.         bQuotes = True
  425.     Case DB_MEMO
  426.         bQuotes = True
  427.     Case Else
  428.         bQuotes = False
  429.     End Select
  430.  
  431.     If IsNull(ds.Recordset(sFldName)) Then
  432.         vValue = er_NullValue(ds.Recordset(sFldName))
  433.         sValue = vValue
  434.     Else
  435.         sValue = LTrim(RTrim(ds.Recordset(sFldName)))
  436.     End If
  437.  
  438.     If bQuotes Then
  439.         sValue = "'" & sValue & "'"
  440.     End If
  441.  
  442.     er_SQLValue = sValue
  443.  
  444. End Function
  445.  
  446. Function erwAddDisplayFieldTranslation(ctlData As Data, strFieldName As String, varValue As Variant, udtTranslateList() As TranslateItem, nListCount As Integer)
  447.     Dim nTmpListCount As Integer
  448.     Dim nTmpListBound As Integer
  449.     Dim udtTmpTranslateItem As TranslateItem
  450.  
  451.     nTmpListCount = nListCount
  452. '   nTmpListBound = UBound(udtTranslateList)
  453.  
  454. '    If nTmpListBound = nTmpListCount Then
  455. '        ReDim udtTranslateList(nTmpListBound + 20)
  456. '    End If
  457.  
  458.     udtTmpTranslateItem.Item = ctlData.Recordset.Fields(strFieldName).OrdinalPosition
  459.     udtTmpTranslateItem.Value = varValue
  460.     udtTranslateList(nTmpListCount) = udtTmpTranslateItem
  461.  
  462.     erwAddDisplayFieldTranslation = nTmpListCount + 1
  463. End Function
  464.  
  465. Function erwDoDisplayFieldTranslation(ctlData As Data, TranslateList() As TranslateItem, nListCount As Integer)
  466.     Dim i As Integer
  467.     Dim nCount As Integer
  468.  
  469.     For i = 0 To nListCount - 1
  470.         If TranslateList(i).Item >= 0 Then
  471.             ctlData.Recordset.Fields(TranslateList(i).Item) = TranslateList(i).Value
  472.             nCount = nCount + 1
  473.         End If
  474.     Next
  475.     erwDoDisplayFieldTranslation = True
  476. End Function
  477.  
  478. Sub erwGetNewListField(ListCtrl As Control, DataCtrl As Data, FieldName As String, ListItems() As ListItem, bNoClick As Integer)
  479.     Dim GstrCount As Integer
  480.     Dim GStrIndex As Integer
  481.     Dim ListCount As Integer
  482.     Dim i As Integer
  483.     Dim FieldValue As String
  484.     Dim DisplayValue As String
  485.  
  486.     Err = 0
  487.     GStrIndex = -1
  488.     On Error Resume Next
  489.     If IsNull(DataCtrl.Recordset.Fields(FieldName)) Then
  490.         FieldValue = ""
  491.     Else
  492.         FieldValue = Trim(DataCtrl.Recordset.Fields(FieldName))
  493.     End If
  494.     GstrCount = UBound(ListItems)
  495.     For i = LBound(ListItems) To GstrCount - 1
  496.         If ListItems(i).DataVal = FieldValue Then
  497.             GStrIndex = i
  498.             DisplayValue = ListItems(i).DisplayVal
  499.             Exit For
  500.         End If
  501.     Next
  502.  
  503.     If GStrIndex = -1 Then
  504.         bNoClick = True
  505.         ListCtrl.ListIndex = -1
  506.         bNoClick = False
  507.         If TypeOf ListCtrl Is ComboBox Then
  508.             bNoClick = True
  509.             ListCtrl.Text = FieldValue
  510.             bNoClick = False
  511.         End If
  512.     Else
  513. '                ListCtrl.Text = DisplayValue
  514.         ListCount = ListCtrl.ListCount
  515.         For i = 0 To ListCount - 1
  516.             If ListCtrl.ItemData(i) = GStrIndex Then
  517.                 bNoClick = True
  518.                 ListCtrl.ListIndex = i
  519.                 bNoClick = False
  520.                 Exit For
  521.            End If
  522.         Next
  523.     End If
  524. End Sub
  525.  
  526. Function erwSetNewListField(ListCtrl As Control, DataCtrl As Data, FieldName As String, ListItems() As ListItem, bValidate As Integer, bNoClick As Integer)
  527.     Dim i As Integer
  528.     Dim ListIndex As Integer
  529.     Dim GStrIndex As Long
  530.     Dim FieldValue As String
  531.     Dim bRetVal
  532.  
  533.     bRetVal = True
  534.     Err = 0
  535.     On Error Resume Next
  536.     ListIndex = ListCtrl.ListIndex
  537.  
  538.         'If no list selection, see if typed in text is on list and select it if so
  539.     If ListIndex = -1 Then
  540.         If TypeOf ListCtrl Is ComboBox Then
  541.                 For i = 0 To ListCtrl.ListCount - 1
  542.                     If ListCtrl.List(i) = ListCtrl.Text Then
  543.                         bNoClick = True
  544.                         ListCtrl.ListIndex = i
  545.                         bNoClick = False
  546.                         Exit For
  547.                     End If
  548.                 Next
  549.                 End If
  550.         End If
  551.  
  552.     'If still no selection, do validation/translation
  553.     ListIndex = ListCtrl.ListIndex
  554.         If ListIndex = -1 Then
  555.             If bValidate Then
  556.                 bRetVal = False
  557.             Else
  558.                 DataCtrl.Recordset.Fields(FieldName) = ListCtrl.Text
  559.             End If
  560.         Else
  561.             GStrIndex = ListCtrl.ItemData(ListIndex)
  562.             FieldValue = ListItems(GStrIndex).DataVal
  563.             DataCtrl.Recordset.Fields(FieldName) = FieldValue
  564.     End If
  565.  
  566.     erwSetNewListField = bRetVal
  567. End Function
  568.  
  569. Sub MoveFromCurrRow(ds As Data, Optional bLastRecord As Variant)
  570.     On Error GoTo MoveFrom_Handler
  571.  
  572.     If bLastRecord Then
  573.         ds.Recordset.MoveLast
  574.     Else
  575.         ds.Recordset.MoveNext
  576.     End If
  577.     
  578.     If ds.Recordset.EOF Then
  579.         If ds.Recordset.RecordCount > 0 Then
  580.             ds.Recordset.MovePrevious
  581.         Else
  582.             ds.Recordset.AddNew
  583.         End If
  584.     End If
  585.  
  586.     Exit Sub
  587.  
  588. MoveFrom_Handler:
  589.     Select Case Err
  590.         Case 3021   ' Error: No current record
  591.             Resume Next
  592.  
  593.         Case Else
  594.             er_DisplayError (Err)
  595.             Resume Next
  596.     End Select
  597.  
  598. End Sub
  599.  
  600.  
  601. Public Sub er_NewButton(Frm As Form, ds As Data, nNoRepos As Integer, bUpdateFailed As Integer)
  602.  
  603.     bUpdateFailed = False   'MAR, MB2
  604.     'If er_CurrRowExists(ds) And ds.EditMode <> dbEditNone Then  'MAR line replaced
  605.     If ds.EditMode <> dbEditNone Then
  606.         er_DS_Update Frm, ds, nNoRepos, bUpdateFailed
  607.     End If
  608.  
  609.     If Not bUpdateFailed Then   'MAR
  610.         ds.Recordset.AddNew
  611.     End If  'MAR
  612.  
  613. End Sub
  614.  
  615. Public Sub er_LoadList(ListCtrl As Control, ListItems() As ListItem)
  616.     Dim i As Integer
  617.  
  618.     For i = LBound(ListItems) To UBound(ListItems) - 1
  619.         ListCtrl.AddItem ListItems(i).DisplayVal
  620.         ListCtrl.ItemData(ListCtrl.NewIndex) = i
  621.     Next
  622. End Sub
  623.  
  624. Public Function er_ErrorPrompt(ErrNum As Integer, sQuestion As String, nButtons As Integer, sTitle As String)
  625.     Dim sMsg As String
  626.  
  627.     If sQuestion = "" Then
  628.         sQuestion = "Do you wish to retry the operation?"
  629.         nButtons = vbYesNo Or vbExclamation
  630.     End If
  631.  
  632.     If sTitle = "" Then
  633.         sTitle = "Application Error"
  634.     End If
  635.  
  636.     Beep
  637.     sMsg = "Error:" & Str(ErrNum) & " - " & Error(ErrNum)
  638.     sMsg = sMsg + String(2, Chr(13)) & sQuestion
  639.     er_ErrorPrompt = MsgBox(sMsg, nButtons, sTitle)
  640.  
  641. End Function
  642.  
  643. Public Function er_ActionNeedsUpdate(Action As Integer)
  644.     Select Case Action
  645.         Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST
  646.             er_ActionNeedsUpdate = True
  647.         Case DATA_ACTIONADDNEW, DATA_ACTIONDELETE
  648.             er_ActionNeedsUpdate = True
  649.         Case DATA_ACTIONCLOSE, DATA_ACTIONUNLOAD
  650.             er_ActionNeedsUpdate = True
  651.         Case DATA_ACTIONBOOKMARK
  652.             er_ActionNeedsUpdate = True
  653.         Case Else
  654.             er_ActionNeedsUpdate = False
  655.     End Select
  656. End Function
  657.  
  658. Public Function er_DS_FieldsAvailable(ds As Data)
  659.     er_DS_FieldsAvailable = er_CurrRowExists(ds) Or ds.EditMode <> DATA_EDITNONE
  660. End Function
  661.  
  662.  
  663. Public Sub er_SaveChangedFlags(axCtrl() As Control, abFlag() As Integer)
  664.     Dim iMax As Integer
  665.     Dim i As Integer
  666.     
  667.     iMax = UBound(axCtrl)
  668.  
  669.     For i = LBound(axCtrl) To iMax - 1
  670.         abFlag(i) = axCtrl(i).DataChanged
  671.     Next i
  672.     
  673. End Sub
  674.  
  675. Public Sub er_RestoreChangedFlags(axCtrl() As Control, abFlag() As Integer)
  676.     Dim iMax As Integer
  677.     Dim i As Integer
  678.     
  679.     iMax = UBound(axCtrl)
  680.  
  681.     For i = LBound(axCtrl) To iMax - 1
  682.         axCtrl(i).DataChanged = abFlag(i)
  683.     Next i
  684.  
  685. End Sub
  686.  
  687. Public Sub er_ClearChangedFlags(axCtrl() As Control, abFlag() As Integer)
  688.     Dim iMax As Integer
  689.     Dim i As Integer
  690.     
  691.     iMax = UBound(axCtrl)
  692.  
  693.     For i = LBound(axCtrl) To iMax - 1
  694.         axCtrl(i).DataChanged = False
  695.         abFlag(i) = False
  696.     Next i
  697.  
  698. End Sub
  699.  
  700. ' Translates a data value into a display value using the specified ListItem array
  701. ' sDataVal: (Input)The data value to translate
  702. ' axList(): (Input) The ListItem array
  703. ' sDisplayVal: (Output) The translated value
  704. ' Returns: True if sDataVal was found in the list, sDisplayVal is the translated value.
  705. '          False if sDataVal was not found in the list, sDisplayVal is sDataVal.
  706. '==================================================================================
  707. Public Function er_GetDisplayValue(sDataVal As String, axList() As ListItem, sDisplayVal As String)
  708.     Dim iMax As Integer
  709.     Dim i As Integer
  710.     Dim sTrimmedString As String
  711.     
  712.     sTrimmedString = Trim(sDataVal)
  713.     iMax = UBound(axList)
  714.     
  715.     For i = LBound(axList) To iMax - 1
  716.         If sTrimmedString = axList(i).DataVal Then
  717.             sDisplayVal = axList(i).DisplayVal
  718.             er_GetDisplayValue = True
  719.             Exit Function
  720.         End If
  721.     Next i
  722.     
  723.     er_GetDisplayValue = False
  724.     sDisplayVal = sTrimmedString
  725.  
  726. End Function
  727.  
  728. ' Translates a display value into a data value using the specified ListItem array
  729. ' sDisplayVal: (Input)The display value to translate
  730. ' axList(): (Input) The ListItem array
  731. ' sDataVal: (Output) The translated value
  732. ' Returns: True if sDisplayVal was found in the list, sDataVal is the translated value.
  733. '          False if sDisplayVal was not found in the list, sDataVal is sDisplayVal.
  734. '==================================================================================
  735. Public Function er_GetDataValue(sDisplayVal As String, axList() As ListItem, sDataVal As String)
  736.     Dim iMax As Integer
  737.     Dim i As Integer
  738.     
  739.     iMax = UBound(axList)
  740.     
  741.     For i = LBound(axList) To iMax - 1
  742.         If sDisplayVal = axList(i).DisplayVal Then
  743.             sDataVal = axList(i).DataVal
  744.             er_GetDataValue = True
  745.             Exit Function
  746.         End If
  747.     Next i
  748.     
  749.     er_GetDataValue = False
  750.     sDataVal = sDisplayVal
  751.  
  752. End Function
  753.